﻿@{
    Layout = "../Shared/_Default.cshtml";
    var t_item = (Model.Translations as IEnumerable<dynamic>)
        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
            JDM.Int32(Svc.Localization.Language.EntityID));
    ViewBag.PageTitle = T(Res.Name("Title"), t_item != null ? JDM.String(t_item.Name) : String.Empty);
    ViewBag.PageHistory = true;
}

@section Breadcrumb
{
    @{
        Html.RenderPartial("_Breadcrumb", (object)Model.Categories);
    }
}
@section Toolbar
{
    <a href="@Url.Action(Loc.Act("Index").Ctrl("Item").Area("Store").Set(new
    {
        itemID = JDM.Int32(Model.EntityID)
    }).Localized())">@T(Res.Name("Store"))</a>
    @if(JDM.HasFlags(Model.Flags, "CommentAllowed") &&
        (Svc.IsAuthenticated || JDM.HasFlags(Model.Flags, "AnonCommentAllowed")))
    {
        <span class="separator">&middot;</span>
        <a href="@Url.Action(Loc.Act("Comment").Ctrl("Feedback").Area("Wizard").Set(new
        {
            tgtID = JDM.Int32(Model.EntityID),
            tgtType = "catalogitem"
        }).Localized())">@T(Res.Name("Comment"))</a>
    }
}
@section Sidebar
{
    @if(JDM.HasFlags(Model.Flags, "RatingAllowed"))
    {
        <div class="box">
            <section>
            @{
                Html.RenderPartial("_Rating");
            }
            </section>
        </div>
    }
    @{
        Html.RenderAction(Loc.Act("_Overview").Ctrl("Supplier").Set(new
        {
            id = JDM.Int32(Model.Supplier.EntityID)
        }).Localized());
        if(Model.FileGroup != null)
        {
            <div class="box">
                <header>
                    <h3>@T(Res.Name("Attachments"))</h3>
                </header>
                <section>
                @{ 
                    Html.RenderAction(Loc.Act("_Attachments").Ctrl("Media").NoArea().Set(new
                    {
                        groupID = JDM.Int32(Model.FileGroup.EntityID)
                    }).Localized()); 
                }
                </section>
            </div>
        }
        var rel = Model.RelatedItems 
            as IEnumerable<dynamic>;
        if(rel.Any())
        {
            <div class="box">
                <header>
                    <h3>@T(Res.Name("Related"))</h3>
                </header>
                <section>
                @{
                    Html.RenderPartial("_Related", rel);
                }
                </section>
            </div>
        }
    }
}
<div class="box @(JDM.HasFlags(Model.Flags, "Promoted") ? "promoted" : String.Empty)">
    <section>
        <table class="columned">
            <tbody>
                <tr>
                    <td>
                    @{
                        Html.RenderPartial("_Image");
                    }
                    </td>
                    <td style="width: 100%;">
                    @{
                        Html.RenderPartial("_ShortDescription");
                        var attrs = Model.Attributes as IEnumerable<dynamic>;
                        if(attrs.Any())
                        {
                            Html.RenderPartial("_Attributes", attrs);
                        }
                    }
                    </td>
                </tr>
            </tbody>
        </table>
    </section>
    <section>
    @{
        Html.RenderPartial("_Description");
    }
    </section>
    <footer>
        <nav>
        @{
            var tags = Model.Tags as IEnumerable<dynamic>;
            if(tags.Any())
            {
                int n = 0;
                <span>@T(Res.Name("Tags"))</span>
                <ul class="bar">
                @foreach(var i in tags)
                {
                    var t_tag = (i.Translations as IEnumerable<dynamic>)
                        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                            JDM.Int32(Svc.Localization.Language.EntityID));
                    <li><a href="@Url.Action(Loc.Act("Index").Set(new
                    {
                        tagID = JDM.Int32(i.EntityID)
                    }).Localized())">@(t_tag != null ? JDM.String(t_tag.Name) : JDM.String(i.EntityID))</a></li>
                    if(n < tags.Count() - 1)
                    {
                        <li>,</li>
                    }
                    n++;
                }
                </ul>
            }
            var groups = Model.Groups as IEnumerable<dynamic>;
            if(groups.Any())
            {
                int n = 0;
                <span class="separator">|</span>
                <span>@T(Res.Name("Groups"))</span>
                <ul class="bar">
                @foreach(var i in groups)
                {
                    var t_group = (i.Translations as IEnumerable<dynamic>)
                        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                            JDM.Int32(Svc.Localization.Language.EntityID));
                    <li><a href="@Url.Action(Loc.Act("Index").Set(new
                    {
                        groupID = JDM.Int32(i.EntityID)
                    }).Localized())">@(t_group != null ? JDM.String(t_group.Name) : JDM.String(i.EntityID))</a></li>
                    if(n < groups.Count() - 1)
                    {
                        <li>,</li>
                    }
                    n++;
                }
                </ul>
            }
        }
        </nav>
    </footer>
</div>
@{
    var spec = Model.Specifications as IEnumerable<dynamic>;
    if(spec.Any())
    {
        <div class="box">
            <header>
                <h3>@T(Res.Name("Specification"))</h3>
            </header>
            <section>
            @{
                Html.RenderPartial("_Specifications", spec);
            }
            </section>
        </div>
    }
}
@if(JDM.HasFlags(Model.Flags, "CommentAllowed"))
{
    <div class="box">
        <header>
            <h3>@T(Res.Name("Comments"), JDM.Int32(Model.CommentCount))</h3>
        </header>
        <section>
        @{
            Html.RenderAction(Loc.Act("_Comments").Set(new
            {
                id = JDM.Int32(Model.EntityID)
            }).Localized());
        }
        </section>
    </div>
}
